package com.xiaojiang.controller;

import cn.dev33.satoken.util.SaResult;
import com.xiaojiang.dto.HouseholdersQueryDto;
import com.xiaojiang.dto.UpdateHouseholderCarDto;
import com.xiaojiang.entity.Householders;
import com.xiaojiang.service.HouseholdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 功能：
 * 作者：小江
 * 日期：2024年10月22日
 */
@RestController
@RequestMapping("/api")
public class HouseholdersController {

    @Autowired
    private HouseholdersService householdersService;
    @GetMapping("/queryHouseholder")
    public SaResult queryHouseholderByCard(@RequestParam String householderCard) {

        return householdersService.queryHouseholderByCard(householderCard);
    }

    @GetMapping("/queryHouseholders")
    public SaResult queryHouseholders(@RequestParam Integer currentPage, @RequestParam Integer pageSize) {
        HouseholdersQueryDto householdersQueryDto = new HouseholdersQueryDto();
        householdersQueryDto.setCurrentPage(currentPage);
        householdersQueryDto.setPageSize(pageSize);

        return householdersService.queryHouseholders(householdersQueryDto);
    }

    @PostMapping("/addHouseholder")
    public SaResult addHouseholder(@RequestBody Householders householders) {
        return householdersService.addHouseholder(householders);
    }

    @DeleteMapping("/deleteHouseholderById/{id}")
    public SaResult deleteHouseholderById(@PathVariable("id") Integer householderId) {
        return householdersService.deleteHouseholderById(householderId);
    }

    @DeleteMapping("/deleteHouseholderByIds")
    public SaResult deleteHouseholderByIds(@RequestParam Integer [] ids) {
        return householdersService.deleteHouseholderByIds(ids);
    }

    @PutMapping("/updateHouseholder")
    public SaResult updateHouseholder(@RequestBody Householders householders) {
        return householdersService.updateHouseholder(householders);
    }

    @PutMapping("/updateHouseholderCar")
    public SaResult updateHouseholderCar(@RequestBody UpdateHouseholderCarDto updateHouseholderCarDto){
        return householdersService.updateHouseholderCar(updateHouseholderCarDto);
    }

}
